--
-- Author:      feilong
-- DateTime:    2018-04-23 17:19:33
-- Description: 日志服务

--
local skynet = require "skynet"

local function init()
	local message_handler = new("logger.message_handler")
	local server_name = skynet.getenv("server_name")
	--收到skynet.error消息 		
	skynet.register_protocol {
		name = "text",
		id = skynet.PTYPE_TEXT,
		unpack = skynet.tostring,
		dispatch = function(_, address, msg)
			--收到消息 					
			local str = string.format("[:%08x] %s", address, msg)	
			print(server_name.."]"..str)		
			message_handler:SaveData(str)
		end		
	}	
	skynet.register_protocol {
		name = "SYSTEM",
		id = skynet.PTYPE_SYSTEM,
		unpack = function(...) return ... end,
		dispatch = function()
			-- reopen signal
			print("SIGHUP")
		end
	}
end


---------------------------------------------------------
-- skynet
---------------------------------------------------------
g.StartService("logger", init)
